﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SMS.DAL.Providers
{
    public class CustomerCreditTransProvider : ProviderBase<SMS.DAL.CutomerCreditTransaction, CustomerCreditTransSearch>
    {
        public override void Insert(CutomerCreditTransaction item)
        {
            Context.CutomerCreditTransactions.AddObject(item);
            Context.SaveChanges();
        }

        public override void Update(CutomerCreditTransaction updatedItem)
        {
            CutomerCreditTransaction obj = this.GetByID(updatedItem.ID);
        }

        public override void Delete(int id)
        {
            Context.CutomerCreditTransactions.DeleteObject(this.GetByID(id));
        }

        public override CutomerCreditTransaction GetByID(int id)
        {
            return (from CCT in Context.CutomerCreditTransactions
                    where CCT.ID == id
                    select CCT).SingleOrDefault();
        }

        public override List<CutomerCreditTransaction> Search(CustomerCreditTransSearch SearchCriteria)
        {
            return (from c in Context.CutomerCreditTransactions
                    where (c.CustomerID == SearchCriteria.CustomerID)
                    && (SearchCriteria.StartDate == null || c.Date > SearchCriteria.StartDate)
                    && (SearchCriteria.EndDate == null || c.Date < SearchCriteria.EndDate)
                    select c).ToList();
        }
    }
}
